#devtools::install_github("slowkow/ggrepel")
library(ggrepel)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.1.2
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ tibble 3.1.8 ✔ dplyr 1.0.7
## ✔ tidyr 1.1.3 ✔ stringr 1.4.0
## ✔ readr 2.0.1 ✔ forcats 0.5.1
## ✔ purrr 0.3.4
## Warning: package 'tibble' was built under R version 4.1.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(readr)
library(dplyr)
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
vizdata <- read_csv("viz1data.csv")
## Rows: 111 Columns: 5── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): field
## dbl (4): mean_borrow, mean_income, sample_borrow, sample_income
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
vizdata1 <- vizdata %>%
filter(field !="Total")
set.seed(123)
ggplot(vizdata1, aes(x=mean_borrow,y=mean_income,label=field)) +
geom_point(size = 2.5, color = "#00AFBB") +
geom_text_repel(aes(label=field), size=2.25, box.padding = 0.5, segment.size = 0.25) +
xlim(3500,15000) + ylim(60000,110000) +
theme_classic() +
xlab("Mean Cumulative Amount Borrowed For Undergrad in 2016") +
ylab("Mean Parents' Income") +
theme(panel.border = element_rect(color = "black", fill = NA, size = 1))

fig <- plot_ly(vizdata1, x = ~mean_borrow, y = ~mean_income, text = vizdata1$field, type = 'scatter', mode = 'markers', name = 'Tips')
fig